//引入axios

import axios from 'axios'
import { ElMessageBox } from 'element-plus'
//配置axios
let http = axios.create({
    //基础地址
    baseURL: '/api',
    //超时设置
    timeout: 1000 * 10,
    //是否携带凭据
    withCredentials: true
})

//配置拦截器

//请求拦截器

http.interceptors.request.use(config => {
    return config
})

//响应拦截器
http.interceptors.response.use(config => {

    if (config.data.state) {
        //当响应正常时直接返回
        return config
    } else {
        let aaa = ['/sms/send']
        // console.log(config.config.url);
        let a = aaa.includes(config.config.url)
        if (!a) {
            ElMessageBox.alert(config.data.msg, '警告', { type: 'error' })

        }
        return Promise.reject(config.data.msg)
    }
})

export default http